package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @LogAnno
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        activityService.deleteById(id);
        return Result.success();
    }
    @LogAnno
    @PutMapping
    public Result update(@RequestBody Activity activity){
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id){
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @GetMapping
    public Result page(
            @RequestParam(name = "channel", required = false) Integer channel,
            @RequestParam(name = "type", required = false) Integer type,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "page", defaultValue = "1") Integer page,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        PageResult<Activity> pageResult = activityService.page(channel, type,status, page, pageSize);
        return Result.success(pageResult);
    }
    @LogAnno
    @PostMapping
    public Result add(@RequestBody Activity activity){
        activityService.add(activity);
        return Result.success();
    }
    @GetMapping("/type/{type}")
    public Result getActivityByType(@PathVariable String type) {
        List<Activity> list = activityService.getActivityByType(type);
        return Result.success(list);
    }
}
